﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CNVP.Framework;
using CNVP.Framework.Utils;
using CNVP.Config;
using CNVP.JShop.UI;

namespace CNVP.JShop.BLL
{
    public class BLLCheckAdmin 
    {
        /// <summary>
        /// 判断权限
        /// </summary>
        /// <param name="page">Page</param>
        /// <param name="FileId">页面ID，0时为正常</param>
        /// <returns></returns>
        public static bool LoginOk(System.Web.UI.Page page, int FileId)
        {
            if (string.IsNullOrEmpty(AdminPage.AdminName))
            {
                MessageUtils.Write("<script>alert('您还没有登录，请先登录！');top.location.href=\"" + Config.UIConfig.InstallDir + Config.UIConfig.AdminDir + "/Login.aspx\"</script>");
                return false;
            }
            else
            {
                if (FileId == 0)
                {
                    return true;//管理员，正常
                }
                else
                {
                    int RoleID = AdminPage.RoleID; //角色ID
                    IList<Model.CNVP_AdminRoleMenu> model = new BLL.CNVP_AdminRoleMenu().GetAdminRoleID_CNVP_AdminRoleMenuByMenuID(FileId);
                    if (model.Count > 0)
                    {
                        foreach (Model.CNVP_AdminRoleMenu m in model)
                        {
                            if (m.AdminRoleID == RoleID)
                            {
                                return true;
                            }
                        }
                        BasePage.MessageBoxGoHistory("您没有权限，请联系管理员！");
                        return false;
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }
    }
}
